﻿Imports CapaEntidadesNegocio
Imports System.Data.SqlClient


Public Class BancoAD

    Private conn As SqlConnection
    Private comando As New SqlCommand
    Private obj As BancoEN


    Public Sub New()

        Dim objConexion As New Conexion
        conn = objConexion.abrir
        comando.Connection = conn

    End Sub

    Public Sub insertar(ByVal objBancoEN As BancoEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_banco_i"

        Dim pNombre As New SqlParameter("@nombre", SqlDbType.VarChar)
        pNombre.Value = objBancoEN._nombre
        pNombre.Direction = ParameterDirection.Input
        comando.Parameters.Add(pNombre)



        comando.ExecuteNonQuery()
        comando.Parameters.Clear()





    End Sub


    Public Sub eliminar(ByVal objBancoEN As BancoEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_banco_d"

        Dim pId As New SqlParameter("@idBanco", SqlDbType.Int)
        pId.Value = objBancoEN._idBanco
        pId.Direction = ParameterDirection.Input
        comando.Parameters.Add(pId)



        comando.ExecuteNonQuery()
        comando.Parameters.Clear()





    End Sub

    Public Sub modificar(ByVal objBancoEN As BancoEN)


        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_banco_u"

        Dim pNombre As New SqlParameter("@nombre", SqlDbType.VarChar)
        pNombre.Value = objBancoEN._nombre
        pNombre.Direction = ParameterDirection.Input
        comando.Parameters.Add(pNombre)

        Dim pId As New SqlParameter("@idBanco", SqlDbType.Int)
        pId.Value = objBancoEN._idBanco
        pId.Direction = ParameterDirection.Input
        comando.Parameters.Add(pId)



        comando.ExecuteNonQuery()
        comando.Parameters.Clear()



    End Sub


    Public Function consultar() As List(Of BancoEN)

        Dim objBanco As BancoEN
        Dim lstobjBancoEN As List(Of BancoEN)

        lstobjBancoEN = New List(Of BancoEN)

        comando.CommandType = CommandType.StoredProcedure
        comando.CommandText = "usp_banco_s"




        Dim reader As SqlDataReader = comando.ExecuteReader()

        If reader.HasRows Then
            While reader.Read()

                objBanco = New BancoEN

                objBanco._idBanco = reader("idBanco")
                objBanco._nombre = reader("nombre")
                
                lstobjBancoEN.Add(objBanco)

            End While

        End If


        reader.Close()
        comando.Parameters.Clear()
        Return lstobjBancoEN



    End Function



End Class
